package fun.easycode.webterminal.adapter.api;

import fun.easycode.webterminal.common.contract.PageDTO;
import fun.easycode.webterminal.common.contract.R;
import fun.easycode.webterminal.service.MachineGroupService;
import fun.easycode.webterminal.service.cmd.MachineGroupPageQry;
import fun.easycode.webterminal.service.cmd.MachineGroupSaveCmd;
import fun.easycode.webterminal.service.dto.MachineGroupDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "分组")
@RestController
@RequestMapping("/api/machine-group")
public class MachineGroupApi {

    private final MachineGroupService machineGroupService;

    @Autowired
    public MachineGroupApi(MachineGroupService machineGroupService) {
        this.machineGroupService = machineGroupService;
    }

    @GetMapping("/page")
    @Operation(summary = "分页查询分组")
    public R<PageDTO<MachineGroupDTO>> page(MachineGroupPageQry cmd) {
        return machineGroupService.page(cmd);
    }

    @PostMapping("/save")
    @Operation(summary = "保存分组(新建/编辑)")
    public R<String> save(@RequestBody MachineGroupSaveCmd cmd) {
        return machineGroupService.save(cmd);
    }

    @GetMapping("/get-by-id")
    @Operation(summary = "根据id查询分组")
    public R<MachineGroupDTO> getById(@RequestParam String id) {
        return machineGroupService.getById(id);
    }

    @Operation(summary = "删除分组")
    @PostMapping("/delete")
    public R<String> delete(@RequestParam String id) {
        return machineGroupService.delete(id);
    }
}
